<template>  
    <div class="comment-container">
        <div class="comment">
                <textarea rows="3" class="form-control" v-model="content"></textarea>
                <button class="btn btn-success" @click="giveComment">发表</button>
        </div>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                content: ''
            }
        },
        methods: {
            giveComment() {
                var _this = this
                if (this.content != '') {
                    $.ajax({
                        url: 'http://127.0.0.1:5000/api/article/givecomment',
                        dataType: 'json',
                        type: 'POST',
                        crossDomain: true,
                        async: true,
                        data: {
                            fparentid: '0',
                            fgrandid: _this.$route.params.id,
                            content: _this.content
                        },
                        success(res) {
                            _this.$parent.getComment()
                            _this.content = ''
                            _this.$Notice.success({
                                title:'提醒',
                                desc:'评论成功！'
                            });
                            _this.$emit('addComment')
                        },
                        error(res) {
                            console.log(res)
                        }
                    })
                }
            }
        },
        props: {
            data: ''
        }
    }
</script>
<style>
    .comment button {
        float: right;
        margin-top: 5px;
        margin-bottom: 20px;
    }
</style>